package com.yidu.StockControl.controller;

import com.yidu.StockControl.entity.SecurityInventory;
import com.yidu.StockControl.service.SecurityInventoryService;
import com.yidu.Util.util.Dbutil;
import com.yidu.Util.util.TableIdUtil;
import com.yidu.Util.util.TableNameUtil;
import com.yidu.Util.util.TableTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  证券应收应付库存        证券应收应付库存            证券应收应付库存
 */
@RestController
public class SecurityInventoryController {
    @Autowired
    private SecurityInventoryService securityInventoryService;
    @Autowired
    Dbutil dbutil;

    @RequestMapping("/selectSecurityInventory")
    @ResponseBody
    public Map selectSecurityInventory(String securityInventoryTime,String securityType, int page, int limit) {


        List<SecurityInventory> list = securityInventoryService.selectSecurityInventory(securityInventoryTime,securityType,page, limit);
        int count = securityInventoryService.selectSecurityInventoryCount();
        Map map = new HashMap();
        map.put("code", "0");
        map.put("msg", ":");
        map.put("count", count);
        map.put("data", list);
        return map;
    }

    @RequestMapping("/insertSecurityInventory")
    @ResponseBody
    public int insertSecurityInventory(SecurityInventory securityInventory, HttpServletRequest request){
        HttpSession session = request.getSession();
        String fundId = (String) session.getAttribute("fundId");
        String maxId3 = dbutil.getMaxId3(TableIdUtil.SASD, TableNameUtil.SI, TableTimeUtil.SASTime, securityInventory.getSecurityInventoryTime());
        securityInventory.setSecurityInventoryId(maxId3);
        securityInventory.setFundId(fundId);
        int i = securityInventoryService.insertSecurityInventory(securityInventory);
        return i;
    }

    @RequestMapping("/updateSecurityInventory")
    @ResponseBody
    public void  updateSecurityInventory(SecurityInventory securityInventory){
        securityInventoryService.updateSecurityInventory(securityInventory);
    }

    @RequestMapping("/deleteSecurityInventory")
    @ResponseBody
    public void  deleteSecurityInventory(String securityInventoryId){
        securityInventoryService.deleteSecurityInventory(securityInventoryId);
    }
}



